1 <?php
2 session_start();
// Use session variable on this page. This function must put on the top of page.
3 if
(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
4 header(
"location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
5 }

6 else

7 {
8     include_once
"db.php";
9     error_reporting (E_ALL ^ E_NOTICE);
10     
if(isset($_GET['id']) && isset($_GET['table']))
11     {
12     $id=$_GET[
'id'];
13     $tablename=$_GET[
'table'];
14     $
return=$_GET['return'];
15     
16     $result =$db->query(
"SELECT * FROM stock_entries WHERE stock_id='$id'");
17   
while ($line = $db->fetchNextObject($result)) {
18             
19                 $difference=$db->queryUniqueValue(
"SELECT quantity FROM stock_entries WHERE id=$line->id");
20                 
21                 $name=$db->queryUniqueValue(
"SELECT stock_name FROM stock_entries WHERE id=$line->id");
22                 $result1=$db->query(
"SELECT * FROM stock_entries where id > $line->id");
23                 
while ($line2 = $db->fetchNextObject($result1)) {
24                 $osd=$line2->opening_stock - $difference;
25                 $csd=$line2->closing_stock - $difference;
26                 $cid=$line2->id;
27                 $db->execute(
"UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
28                     
29                 }
30                 $total = $db->queryUniqueValue(
"SELECT quantity FROM stock_avail WHERE name='$name'");
31                 $total = $total - $difference;
32                 $db->execute(
"UPDATE stock_avail SET quantity=$total WHERE name='$name'");
33                 $db->execute(
"DELETE FROM stock_entries WHERE id=$line->id");
34     
35     
36     }
37     
38
39     
40     
41     
42     header(
"location:$return?msg=Record Deleted Successfully!&id=$id");
43     }
44         
45
46     
47 }
48 ?>


Gõ tìm kiếm nhanh...